var express = require('express');
var router = express.Router();
let Query=require('../tools/db')
let {api_url}=require('../config/config')

/* 获取banner */
router.get('/banner',async (req, res, next)=>{
  let sql=`SELECT id,title,CONCAT('${api_url}','/upload/',image_src) AS image_src FROM e_banners WHERE isshow='1'`
  let [,result]=await Query(sql)
  res.send({
    code:200,
    msg: 'ok',
    result
  })
})

/* 获取同步课程或者精品课程 */
router.get('/course',async (req, res, next)=>{
  let {type=1}=req.query
  let limit=type==1?8:6
  let sql=`SELECT cid,title,price,CONCAT('${api_url}','/upload/course/',image_src) AS image_src,type_name,area_name,subject_name FROM e_course WHERE type=${type} ORDER BY id DESC LIMIT ${limit}`
  let [,result]=await Query(sql)
  res.send({
    code:200,
    msg: 'ok',
    result
  })
})

module.exports = router;